﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using ThePresenter.ViewModel;

namespace ThePresenter.Network
{
	class Client : ViewModelBase
	{
		private TcpClient _TcpClient;

		private ClientState _State;

		public ClientState State
		{
			get
			{
				return this._State;
			}
			private set
			{
				if (this._State != value)
				{
					this._State = value;
					OnPropertyChanged("State");
				}
			}
		}

		public Client()
		{
			_TcpClient = new TcpClient();
			this.State = ClientState.CREATED;
		}

		public void Connect(string Hostname, int Port)
		{
			// TODO: pokracovat. pri disconnect nejako blbne :P
			if (!_TcpClient.Connected)
			{
				_TcpClient.Connect(Hostname, Port);
				this.State = ClientState.CONNECTED;
			}
		}
		
		public void Connect(IPEndPoint EP)
		{
			_TcpClient.Connect(EP);
			this.State = ClientState.CONNECTED;
		}

		public void Disconnect()
		{
			_TcpClient.Client.Disconnect(true);
			this.State = ClientState.DISCONNECTED;
		}


	}

	enum ClientState { 
		CREATED = 0,
		CONNECTED,
		DISCONNECTED
	}
}
